package atm;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GetPanel extends JPanel implements ActionListener {
    private ATM atm;
    private JButton sureBtn;
    private JButton clearBtn;
    private Icon sureImg = Util.getImageIcon("/images/buttonSure.jpg");
    private Icon clearImg = Util.getImageIcon("/images/buttonClear.jpg");
    private JTextField qukuan=new JTextField();

    public GetPanel(ATM atm){
        this.atm = atm;
        this.setLayout(null);
        this.setOpaque(false);

        JLabel qu=new JLabel("请输入取款金额");
        qu.setBounds(400, 220, 90, 20);
        this.add(qu);

        qukuan.setBounds(510, 220, 90, 20);
        this.add(qukuan);


        sureBtn = new JButton(sureImg);
        sureBtn.setBounds(10, 40, 140, 50);
        this.add(sureBtn);
        sureBtn.addActionListener(this);

        clearBtn = new JButton(clearImg);
        clearBtn.setBounds(10, 100, 140, 50);
        this.add(clearBtn);
        clearBtn.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == sureBtn) {

            atm.switchPanel("menu");
            JOptionPane.showMessageDialog(this,"取款成功，您本次取款金额为："+qukuan.getText());
            atm.getUsers().get(atm.getA()).setMoney(-Double .valueOf(qukuan.getText())+atm.getUsers().get(atm.getA()).getMoney());
        } else if (e.getSource() == clearBtn) {

            atm.switchPanel("menu");
        }
    }
}